package com.nit.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.nit.generate.*;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

/**
 * 生成器枚举类
 *
 * @Auth: 逆天开源-逍遥哥哥
 * @link: 1715656022@qq.com
 * @Date: 2023-07-11
 */
@Getter
@AllArgsConstructor
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum GeneratorTypeEnum implements GenerateInterface {
    IDCARD("gen_idcard", "身份证"),
    CHINESE_NAME("gen_chinese_name", "中文名字"),
    DATE("gen_date", "日期数据"),
    PHONE("gen_phone", "手机号"),
    UUID("gen_uuid", "uuid"),
    COLOR("gen_color", "色值"),
    STRING("gen_string", "字符串"),
    IP_V4("gen_ip4", "IPV4地址"),
    IP_V6("gen_ip4", "IPV6地址"),
    JOB("gen_job", "职业"),
    NUMBER("gen_number", "数字"),
    EMAIL("gen_email", "邮箱"),
    MAC("gen_mac", "mac地址"),
    DOMAIN("gen_domain", "域名地址"),
    QQ("gen_qq", "QQ号码"),
    WECHATID("gen_WeChatID", "微信号码"),
    PLATE("gen_Plate", "车牌号"),
    TANGPOETRY("gen_tangpoetry", "唐诗"),
    IDIOM("gen_idiom", "成语"),
    PORT("gen_port", "端口号"),
    NATION("gen_nation", "民族");


    private final String code;
    private final String name;

    public static GeneratorTypeEnum getGeneratorTypeEnumByCode(String code) {
        return Arrays.stream(GeneratorTypeEnum.values()).filter(a -> a.code.equals(code)).findFirst().orElse(GeneratorTypeEnum.NUMBER);
    }

    public static void main(String[] args) {
//        GeneratorTypeEnum generatorTypeEnum = GeneratorTypeEnum.getGeneratorTypeEnumByCode("gen_idcard");
//        System.out.println(generatorTypeEnum.name);
//        System.out.println(generatorTypeEnum.generate());


        String aa = IDCARD.getResult("IDCARD");
        System.out.print(aa);
    }


    public String getResult(String code) {
        Map<String, Function<String, String>> grantTypeMap = new HashMap<>();
        grantTypeMap.put("IDCARD", resourceId -> {
            System.out.println(resourceId);
            return NitIdcardGenerator.generate();
        });
        grantTypeMap.put("CHINESE_NAME", resourceId -> NitChineseNameGenerator.generate());
        grantTypeMap.put("PHONE", resourceId -> NitPhoneGenerator.generate());
        Function<String, String> result = grantTypeMap.get(code);
        if (result != null) {
            return result.apply("12312321");
        }
        return null;
    }

    @Override
    public String generate(Integer length) {
        switch (this) {
            case IDCARD:
                return NitIdcardGenerator.generate();
            case CHINESE_NAME:
                return NitChineseNameGenerator.generate();
            case DATE:
                return NitDateGenerator.generate();
            case PHONE:
                return NitPhoneGenerator.generate();
            case UUID:
                return NitUUIDGenerator.generate();
            case COLOR:
                return NitColorGenerator.generateHex();
            case STRING:
                if(Objects.nonNull(length)){
                    return NitStringGenerator.generate(length);
                }else{
                    return NitStringGenerator.generate();
                }
            case IP_V4:
                return NitIPGenerator.generateV4();
            case IP_V6:
                return NitIPGenerator.generateV6();
            case JOB:
                return NitJobGenerator.generate();
            case NUMBER:
                if(Objects.nonNull(length)){
                    return NitNumberGenerator.generateInt(length)+"";
                }else{
                    return NitNumberGenerator.generate() + "";
                }
            case EMAIL:
                return NitEmailGenerator.generate();
            case MAC:
                return NitMacGenerator.generate();
            default:
                break;
        }
        return "";
    }
}
